using System;
using System.Collections.Generic;
using System.Text;
using My.IdlConverter.Com;
using My.IdlConverter.Core;
using My.IdlConverter.Core.Util;
using My.IdlConverter.Core.Parsers;

namespace My.IdlConverter.SmartHitHelper
{
    class Searcher
    {
        private static Searcher _instance;
        private IList<Interface> _interfaceList;

        static Searcher()
        {
            _instance = new Searcher();
        }

        public static Searcher Instance
        {
            get { return _instance; }
        }

        public IList<Interface> All
        {
            get { return _interfaceList; }
        }

        public Interface SmartFind(string text)
        {
            foreach (Interface nextInterface in _interfaceList)
            {
                if (nextInterface.Name.IndexOf(text) != -1)
                    return nextInterface;
            }

            return null;
        }

        private Searcher()
        {
            try
            {
                IParser parser = new ComIdlParser();
                string idlFileName = ReflectHelper.ResolvePathByAssembly(System.Reflection.Assembly.GetExecutingAssembly(),"configuration\\WinScriptEngine.idl");
                _interfaceList = parser.Parse(idlFileName) as IList<Interface>;
            }
            catch (Exception)
            {
                System.Diagnostics.Debug.Assert(false);
                _interfaceList = new List<Interface>();
            }
        }
    }
}
